package databaseVersionControl.domain.dml;

import databaseVersionControl.infra.exception.DVCGeneralException;

public class Delete extends DML {

	private String whereStatement;
	
	public Delete from(String table) {
		this.table = table.toUpperCase();
		return this;
	}
	
	public Delete where(String whereStatement) {
		this.whereStatement = whereStatement.toUpperCase();
		return this;
	}
	
	private void validateStatement() {
		if (table == null) throw new DVCGeneralException("Table cannot be null");
		if (whereStatement == null) throw new DVCGeneralException("Cannot delete without where clause.");
	}

	@Override
	public String sqlString() {
		validateStatement();
		
		StringBuilder builder = new StringBuilder("DELETE FROM ");
		builder.append(table);
		builder.append(" WHERE ");
		builder.append(whereStatement);
		
		return builder.toString();
	}
	
}